{% extends "base.html" %}

{% block title %}{{ knyga.antraste|escape }} - {{ application_name }}{% endblock %}

{% block head %}
	{% if debug %}
		<script src="/static/javascript/debug/browser.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/dialog.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/dom.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/event.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/lang.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/offscreen.js" type="text/javascript"></script>
		<script src="/static/javascript/debug/tasklist.js" type="text/javascript"></script>
	{% else %}
		<script src="/static/javascript/biblioteka.js" type="text/javascript"></script>
	{% endif %}

	<script src="/static/javascript/bsn.AutoSuggest_c_2.0.js" type="text/javascript"></script>
	<link rel="stylesheet" href="/static/css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />

	<link rel="alternate" type="application/atom+xml" title="{{ knyga.antraste|escape }}" href="{{ request.path }}?id={{ knyga.key|stringformat:"s"|urlencode }}&amp;output=atom"/>

	<script type="text/javascript">
	//<![CDATA[
	function taisytiKnyga() {
		var form = document.getElementById("knygosforma");
		var dialog = document.getElementById("knygosforma_dialog");
		DialogBox.instance().show(dialog, function() {
			form["autorius"].focus();
		});
	}

	function naujasIrasas() {
		textBox.style.display = "";
		naujasDiv.style.display = "None";
		textBox.value = "";
		textBox.focus();
	}

	function onEditKeyPress(e) {
		if (e.keyCode == 13) {
			cancelEvent(e);
			saveEdit();
		} else if (e.keyCode == 27) {
			cancelEvent(e);
			textBox.style.display = "None";
			naujasDiv.style.display = "";
		}
	}

	function saveEdit() {
		if (textBox.value != "") {
			save();
		} else {
			textBox.style.display = "None";
			naujasDiv.style.display = "";
		}
	}

	function save() {
		form = document.forms["irasas_form"];
		form.submit();
	}
	//]]>
	</script>
	<style type="text/css">

	.grazinta td {
		color: gray;
		text-decoration: line-through;
	}

	h1 {
		font-size: large;
		margin: 0;
	}

	.inbox .top {
		margin-bottom: 5px;
	}

	.inbox .table td {
		border-bottom: 0;
		padding-bottom: 3px;
		padding-top: 3px;
	}

	#publish_info {
		padding-top: 5px;
		padding-bottom: 5px;
	}

	.newtasklist {
		margin-left: 10px;
		margin-top: 5px;
	}

	.newtasklist img {
		vertical-align: middle;
	}

	.newtasklist .text {
		text-decoration: underline;
		color: #0000cc;
	}

	</style>
{% endblock %}

{% block body %}
	<h1>{{ knyga.antraste|escape }}</h1>

		<div class="inbox">
			<form action="/knygaaction.do" method="post">
			<div class="buttons top" style="height: 24px">
				<div class="left corner"></div>
				<div class="right corner"></div>
				<div class="info">
					<span class="count">{{ irasai|length }} įrašas (-ai)</span>
				</div>
				<span class="button"><input type="submit" name="action" value="Ištrinti" onclick="return confirm('Ar tikrai norite neatstatomai ištrinti pažymėtus įrašus?')"/></span>
				<span class="button"><input id="edit_button" type="button" value="Taisyti knygos duomenis" onclick="taisytiKnyga()"/></span>
				<span id="publish_info" style="margin-left: 0.5em">Viešai prieinama kaip <a href="{{ request.uri|escape }}&amp;output=html">HTML</a>, <a href="{{ request.uri|escape }}&amp;output=atom">Atom šaltinis</a></span>
			</div>
			<div class="table">
				<input type="hidden" name="next" value="{{ request.uri|escape }}"/>
				<table id="knygosirasas">
					<tr>
						<th class="checkbox"><input type="checkbox" onclick="pazymeti(this.checked)"/></th>
						<th class="skaitytojas">Skaitytojas</th>
						<th class="data">Išdavimo data</th>
						<th class="data">Grąžinimo data</th>
					</tr>
					{% for irasas in irasai %}
					<tr{% if irasas.grazinta %} class="grazinta"{% endif %} id="row{{ forloop.counter }}">
						<td class="checkbox"><input class="knygacheckbox" type="checkbox" name="irasas" value="{{ irasas.key }}" id="checkbox{{ forloop.counter }}" onclick="atnaujintiParyskinima(this, document.getElementById('row{{ forloop.counter }}'))"/></td>
						<td class="skaitytojas">{{ irasas.skaitytojas|stringformat:"s"|addslashes }}</td>
						<td class="data">{{ irasas.isduota_local|date:"Y-m-d H:i" }}</td>
						<td class="data">{{ irasas.grazinta_local|date:"Y-m-d H:i" }}</td>
					</tr>
					{% endfor %}
				</table>
			</div>
			</form>
			<div class="table">
				<table>
					<tr id="irasas_row">
						<td></td>
						<td class="skaitytojas">
						{% if paskutinis_irasas.grazinta %}
							<form id="irasas_form" action="/knygosisdavimas.do" method="post">
								<div>
									<input type="hidden" name="knyga" value="{{ knyga.key }}"/>
									<input type="hidden" name="next" value="{{ request.uri|escape }}"/>
									<input type="text" name="skaitytojas" id="textbox" style="border: 2px solid silver; padding: 2px; margin: 0; width: 100%; display: none" value=""/>
								</div>
							</form>
						{% else %}
							<form id="irasas_form" action="/knygosgrazinimas.do" method="post">
								<div>
									<input type="hidden" name="next" value="{{ request.uri|escape }}"/>
									<input type="hidden" name="id" value="{{ paskutinis_irasas.key }}"/>
								</div>
							</form>
						{% endif %}
						</td>
						<td class="data"></td>
						<td class="data"></td>
					</tr>
				</table>
				{% if paskutinis_irasas.grazinta %}
					<div id="naujasirasas" class="newtasklist" style="cursor: pointer" onclick="naujasIrasas()"><img src="/static/images/zip-plus.gif" style="width: 14px; height: 14px" alt="Pliusas"/> <span class="text">Naujas įrašas</span></div>
				{% else %}
					<div class="newtasklist" style="cursor: pointer" onclick="save()"><img src="/static/images/zip-minus.gif" style="width: 14px; height: 14px" alt="Minusas"/> <span class="text">Gražinti knygą</span></div>
				{% endif %}
				{% if not irasai %}
					<div class="message">Ši knyga neturi įrašų. Norėdami pradėti, <a href="javascript:naujasIrasas()">sukurkite naują įrašą</a>.</div>
				{% endif %}
			</div>
		</div>

	<div id="knygosforma_dialog" class="dialog" style="display: none">
		<div class="title">Knygos taisymas</div>
		<div class="content">
			<form action="/knygossukurimas.do" method="post" id="knygosforma">
				<div class="form">
					<input type="hidden" name="knyga" value="{{ knyga.key }}"/>
					<input type="hidden" name="next" value="{{ request.uri|escape }}"/>
					<div class="field">
						<div class="name">Numeris</div>
						<div class="value"><input name="numeris" type="text" size="4" value="{{ knyga.numeris }}"/></div>
					</div>
					<div class="field">
						<div class="name">Autorius</div>
						<div class="value"><input name="autorius" type="text" size="70" value="{{ knyga.autorius }}"/></div>
					</div>
					<div class="field">
						<div class="name">Antraštė</div>
						<div class="value"><input name="antraste" type="text" size="70" value="{{ knyga.antraste }}"/></div>
					</div>
					<div class="field">
						<div class="name">Leidykla</div>
						<div class="value"><input name="leidykla" type="text" size="70" value="{{ knyga.leidykla }}"/></div>
					</div>
					<div class="field">
						<div class="name">Miestas</div>
						<div class="value"><input name="miestas" type="text" size="70" value="{{ knyga.miestas }}"/></div>
					</div>
					<div class="field">
						<div class="name">Metai</div>
						<div class="value"><input name="metai" type="text" size="4" value="{% if knyga.metai %}{{ knyga.metai }}{% endif %}"/></div>
					</div>
					<div class="field">
						<div class="name">Klasifikacija</div>
						<div class="value">
							<input name="klasifikacija" id="klasifikacija" type="hidden"/>
							<input id="klasifikacijainput" type="text" size="70" value="{{ knyga.kategorija.kodas|escape }} {{ knyga.kategorija.pavadinimas|escape }}"/>
						</div>
					</div>
					<div class="field">
						<div class="name">Pastabos</div>
						<div class="value"><input name="pastabos" type="text" size="70" value="{{ knyga.pastabos }}"/></div>
					</div>
					<div class="buttons">
						<span class="button"><input type="submit" name="action" value="Taisyti knygą"/></span>
						<span class="button"><input type="button" value="Atšaukti" onclick="DialogBox.instance().close()"/></span>
					</div>
				</div>
			</form>
		</div>
	</div>
{% endblock %}
{% block footer %}
	{% if paskutinis_irasas.grazinta %}
	<script type="text/javascript">

	var as = new AutoSuggest('klasifikacijainput', {
		script: "/kategorijupaieska?",
		varname: "input",
		json: true,
		timeout: 2147483647,
		callback: function (obj) {
			document.getElementById('klasifikacija').value = obj.id;
		}
	});

	var naujasDiv = document.getElementById("naujasirasas");
	var textBox = document.getElementById("textbox");
	Event.addListener(textBox, "keypress", onEditKeyPress);
	Event.addListener(textBox, "blur", saveEdit);

	</script>
	{% endif %}
{% endblock %}

